package com.web.entity.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * @author liuxuhuang
 * @date 2023年03月30日 21:11
 */
@ApiModel()
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString
public class UserLoginDTO {
    /**
     * 用户名
     */
    @ApiModelProperty("用户名(用户名、邮箱)")
    @NotBlank(message = "用户名不能为空")
    private String username;

    /**
     * 密码
     */
    @ApiModelProperty("密码")
    @NotBlank(message = "密码不能为空")
    @Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$", message = "密码要包含字母和数字，要求8-16位")
    private String password;
    /**
     * 表单key
     */
    @ApiModelProperty("表单key")
    @NotBlank(message = "表单key不能为空")
    private String formKey;
    /**
     * 验证码
     */
    @ApiModelProperty("验证码")
    @NotBlank(message = "验证码不能为空")
    @Size(min = 4, max = 6, message = "验证码为4-6位")
    private String code;

    public String getUsername() {
        return username.replaceAll(" ", "");
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password.replaceAll(" ", "");
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFormKey() {
        return formKey.replaceAll(" ", "");
    }

    public void setFormKey(String formKey) {
        this.formKey = formKey;
    }

    public String getCode() {
        return code.replaceAll(" ", "");
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof UserLoginDTO)) return false;

        UserLoginDTO that = (UserLoginDTO) o;

        if (!getUsername().equals(that.getUsername())) return false;
        if (!getPassword().equals(that.getPassword())) return false;
        return getCode().equals(that.getCode());
    }

    @Override
    public int hashCode() {
        int result = getUsername().hashCode();
        result = 31 * result + getPassword().hashCode();
        result = 31 * result + getCode().hashCode();
        return result;
    }
}
